#pragma once
#include <iostream>
#include "Reactor.hpp"
#include "Common.hpp"
#include "Socket.hpp"
// 管理每一个文件描述符
class Reactor; // 前置声明  
class Channel; // 前置声明  
class Connection
{
public:
    using handler_t =std::function<void(std::shared_ptr<Channel>)>;
    Connection():handler(nullptr),events(0), owner(nullptr) {}
    virtual void Recever() = 0;
    virtual void Sender() = 0;
    virtual void Excepter() = 0;
    void setEvents(uint32_t events)
    {
        this->events = events;
    }
    uint32_t getEvents() const
    {
        return events;
    }
    virtual int getFd() 
    {
        return -1;
    }
    ~Connection() {}
    void setOwner(Reactor *owner){
        this->owner = owner;
    }
    Reactor *getOwner() {
        return owner;
    }
    void RegisterHandler(handler_t handler){
        if(handler!=nullptr){
            this->handler = handler;
        }
    }
private:
    //std::string inbuffer;
    //std::string outbuffer;
    // 回指指针
    Reactor *owner;
    //NetAddr client_addr;
    uint32_t events;
public:
    handler_t handler;
};
